package com.android.ailaoshan.index.listener;

import android.content.Context;
import android.support.design.widget.NavigationView;
import android.view.MenuItem;
import android.widget.Toast;

import com.android.ailaoshan.R;
import com.android.ailaoshan.index.MainActivity;

/**
 * 侧边滑动栏事件监听
 */
public class NavigationViewListener {

    private MainActivity mainActivity;
    private Context mContext;

    public NavigationViewListener(MainActivity mainActivity,Context context) {
        this.mainActivity = mainActivity;
        this.mContext = context;
    }

    public void setNavigationListen(){
        if(this.mainActivity != null){
            NavigationView navigationView =
                    mainActivity.findViewById(R.id.navigation_left_content_item);

            navigationView.setNavigationItemSelectedListener(navigationItemSelectedListener);
        }
    }

    /**
     * 侧滑栏菜单项点击事件监听
     */
    private NavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener
            = new NavigationView.OnNavigationItemSelectedListener(){
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            int id = item.getItemId();

            if (id == R.id.navigation_left_item1) {
                Toast.makeText(mContext,"点击了菜单项第一项",Toast.LENGTH_SHORT).show();
            } else if (id == R.id.navigation_left_item2) {

            } else if (id == R.id.navigation_left_item3) {

            } else if (id == R.id.navigation_left_item4) {

            } else if (id == R.id.navigation_left_item5) {

            }else if (id == R.id.navigation_left_item6){

            }

            mainActivity.closeDrawerLayout();

            return true;
        }
    };
}
